package com.qf.electronic.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.electronic.common.R;
import com.qf.electronic.dto.RoleDto;
import com.qf.electronic.dto.RoleStateDto;
import com.qf.electronic.pojo.Role;
import com.qf.electronic.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wu
 * @since 2023-05-04
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @PostMapping
    public R<Boolean> addRole(@RequestBody Role role){
        return R.ok(roleService.save(role));
    }

    @PutMapping
    public R<Boolean> updateRole(@RequestBody Role role){
        return R.ok(roleService.updateById(role));
    }

    @PutMapping("/state")
    public R<Boolean> updateRoleState(@RequestBody RoleStateDto stateDto){
        return R.ok(roleService.updateRoleState(stateDto));
    }

    @GetMapping
    public R<Page<Role>> searchRoles(RoleDto roleDto){
        return R.ok(roleService.searchRoles(roleDto));
    }

    @DeleteMapping
    public R<Boolean> deleteRoles(@RequestParam("roleIds")List<Integer> roleIds){
        return R.ok(roleService.removeByIds(roleIds));
    }
}

